feat: Add support for downaloding documents/profile pictures (2fa token needed), expanded homework and general fixes#4
Open
Fefedu973 wants to merge 2 commits intoBlocksHub:mainfrom
Open
Conversation
Introduce download-related types and extend downloader functionality: add src/types/DownloadRequest.ts, export it from index, and implement helpers in Downloader (getDownloadURL/headers/request, getStream refactor, profile photo URL/headers/request and getProfilePhoto). Add clean JSON handling and use configured USER_AGENT/BASE_URL. Add centralized auth header helper in Modules (getAuthHeaders) and improve account/module checks. Update Auth to persist a 2FA token from response headers and removed stray console.log. Add Client.getToken2FA() getter and broaden DOWNLOADER_URL param types in endpoints to accept string|number. Small API surface and behavior changes to support 2FA flows and binary downloads.
Introduce centralized binary fetching in Downloader (executeBinaryRequest) and helper APIs (getBinaryDownloadRequest, getDownloadBinary, getCloudFileRequest, getCloudFile) plus content-disposition parsing (getResponseFileName, decodeContentDispositionValue). Extend BinaryResponse with contentDisposition and fileName. Export CloudFile and several homework-related types from index.ts. Refactor HomeworkUpcoming: add HomeworkUpcomingItem interface and change HomeworkUpcoming to map ISO dates to arrays of items.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several improvements and new features, primarily focused on enhancing file download capabilities, supporting 2FA tokens throughout authentication and requests (necessary for the downloàad feature), and expanding type definitions for homework and downloads. The most significant changes are grouped below.
Downloader module enhancements:
DownloaderModulesclass to support binary file downloads, cloud file access, and profile photo retrieval, including new helper methods for constructing requests, parsing response headers, and handling authentication headers.DownloadRequest.ts, includingDownloadRequest,BinaryRequest,BinaryResponse, and related parameter types.DOWNLOADER_URLfunction now accepts both string and number file IDs for improved flexibility.2FA token propagation and handling:
Credentialinterface now includes an optionaltoken2faproperty to store the 2FA token.AuthModulesis updated to extract and store the2fa-tokenheader when present, ensuring 2FA tokens are preserved and used for subsequent requests. [1] [2]getToken2FAmethod is added to theClientclass for convenient retrieval of the current 2FA token.Modulesclass now includes agetAuthHeadershelper that automatically attaches both the main token and 2FA token to all requests if present.Homework and type definition updates:
Homework,HomeworkDate,HomeworkEntityType,HomeworkLessonContent,HomeworkSubject,HomeworkTags, andHomeworkUpcoming.HomeworkUpcomingis updated:HomeworkUpcomingItemis now an interface, andHomeworkUpcomingis a record mapping ISO dates to arrays of these items, improving type safety and clarity. [1] [2]General improvements and bug fixes:
Modulesclass, making module support validation more robust and accurate. [1] [2]Type exports for new features:
src/index.tsfor all newly introduced types, making them available for consumers of the package.